﻿#pragma once

#include "../../Server/MirEnvir/Envir.h"
#include "../../Shared/Data/Stat.h"
#include "../../Shared/Enums.h"
#include <string>
#include <vector>
#include <limits>
#include <stdexcept>
#include <any>
#include "exceptionhelper.h"
#include "../../stringhelper.h"
#include "../../tangible_filesystem.h"

using namespace Server::MirEnvir;

namespace Server::Database
{
    class ItemInfoFormNew : public System::Windows::Forms::Form
    {
    public:
        virtual ~ItemInfoFormNew()
        {
            delete StatEnums;
            delete BindEnums;
            delete SpecialEnums;
            delete Table;
            delete components;
            delete itemInfoGridView;
            delete panel1;
            delete panel2;
            delete groupView;
            delete rbtnViewAll;
            delete rbtnViewBinding;
            delete rbtnViewBasic;
            delete rbtnViewStats;
            delete rBtnViewSpecial;
            delete panel3;
            delete lblSearch;
            delete txtSearch;
            delete lblFilterType;
            delete drpFilterType;
            delete btnExport;
            delete btnImport;
            delete Modified;
            delete ItemIndex;
            delete ItemName;
            delete ItemType;
            delete ItemGrade;
            delete ItemRequiredType;
            delete ItemRequiredGender;
            delete ItemRequiredClass;
            delete ItemSet;
            delete ItemRandomStatsId;
            delete ItemRequiredAmount;
            delete ItemImage;
            delete ItemShape;
            delete ItemEffect;
            delete ItemStackSize;
            delete ItemSlots;
            delete ItemWeight;
            delete ItemLightRange;
            delete ItemLightIntensity;
            delete ItemDurability;
            delete ItemPrice;
        }

        Server::MirEnvir::Envir *getEnvir() const;

    private:
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
        Array *const StatEnums = Enum::GetValues(typeof(Stat));
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
        Array *const BindEnums = Enum::GetValues(typeof(BindMode));
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
        Array *const SpecialEnums = Enum::GetValues(typeof(SpecialItemMode));

        DataTable *Table;

    public:
        ItemInfoFormNew();

    private:
        void InitializeItemInfoFilters();

        void InitializeItemInfoGridView();

    public:
        template<typename T>
        static DataTable *Enum2DataTable()
        {
            DataTable *enumTable = new DataTable();
            DataColumn tempVar("Value", Enum::GetUnderlyingType(typeid(T)));
            enumTable->Columns->Add(&tempVar);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to the C# 'typeof' operator:
            DataColumn tempVar2("Display", typeof(std::string));
            enumTable->Columns->Add(&tempVar2);
            DataRow *EnumRow;
            for (auto E : Enum::GetValues(typeid(T)))
            {
                EnumRow = enumTable->NewRow();
                EnumRow["Value"] = E;
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
                EnumRow["Display"] = E.ToString();
                enumTable->Rows->Add(EnumRow);
            }

//C# TO C++ CONVERTER TODO TASK: A 'delete enumTable' statement was not added since enumTable was used in a 'return' or 'throw' statement.
            return enumTable;
        }

    private:
        void CreateDynamicColumns();

        void PopulateTable();

        void UpdateFilter();

        void SaveForm();

        DataRow *FindRowByItemName(const std::string &value);

        void itemInfoGridView_CellValidating(std::any sender, DataGridViewCellValidatingEventArgs *e);

        void rbtnViewAll_CheckedChanged(std::any sender, EventArgs *e);

        void rbtnViewBasic_CheckedChanged(std::any sender, EventArgs *e);

        void rbtnViewStats_CheckedChanged(std::any sender, EventArgs *e);

        void rbtnViewBinding_CheckedChanged(std::any sender, EventArgs *e);

        void rBtnViewSpecial_CheckedChanged(std::any sender, EventArgs *e);

        void drpFilterType_SelectedIndexChanged(std::any sender, EventArgs *e);

        void txtSearch_KeyDown(std::any sender, KeyEventArgs *e);

        void btnImport_Click(std::any sender, EventArgs *e);

        void btnExport_Click(std::any sender, EventArgs *e);

        void itemInfoGridView_DefaultValuesNeeded(std::any sender, DataGridViewRowEventArgs *e);

        void itemInfoGridView_UserDeletingRow(std::any sender, DataGridViewRowCancelEventArgs *e);

        void ItemInfoFormNew_FormClosed(std::any sender, FormClosedEventArgs *e);

        void itemInfoGridView_DataError(std::any sender, DataGridViewDataErrorEventArgs *e);


        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::IContainer *components = nullptr;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected:
        void Dispose(bool disposing) override;

        #pragma region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private:
        void InitializeComponent();

        #pragma endregion

        System::Windows::Forms::DataGridView *itemInfoGridView;
        System::Windows::Forms::Panel *panel1;
        System::Windows::Forms::Panel *panel2;
        System::Windows::Forms::GroupBox *groupView;
        System::Windows::Forms::RadioButton *rbtnViewAll;
        System::Windows::Forms::RadioButton *rbtnViewBinding;
        System::Windows::Forms::RadioButton *rbtnViewBasic;
        System::Windows::Forms::RadioButton *rbtnViewStats;
        System::Windows::Forms::RadioButton *rBtnViewSpecial;
        System::Windows::Forms::Panel *panel3;
        System::Windows::Forms::Label *lblSearch;
        System::Windows::Forms::TextBox *txtSearch;
        System::Windows::Forms::Label *lblFilterType;
        System::Windows::Forms::ComboBox *drpFilterType;
        System::Windows::Forms::Button *btnExport;
        System::Windows::Forms::Button *btnImport;
        System::Windows::Forms::DataGridViewCheckBoxColumn *Modified;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemIndex;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemName;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemType;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemGrade;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemRequiredType;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemRequiredGender;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemRequiredClass;
        System::Windows::Forms::DataGridViewComboBoxColumn *ItemSet;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemRandomStatsId;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemRequiredAmount;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemImage;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemShape;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemEffect;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemStackSize;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemSlots;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemWeight;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemLightRange;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemLightIntensity;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemDurability;
        System::Windows::Forms::DataGridViewTextBoxColumn *ItemPrice;
    };
}
